package com.stargazer.ming.ui.base;


import com.stargazer.ming.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

public class MingButton extends FrameLayout {
	private TextView tv;
	private ImageView iv;

	public MingButton(Context context) {
		this(context, null, 0);
	}

	public MingButton(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public MingButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}
	
	private void init(final Context context) {
		{
			final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
			lp.gravity = Gravity.CENTER;
			iv = new ImageView(context);
			iv.setLayoutParams(lp);
			addView(iv);
		}

		{
			final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
			lp.gravity = Gravity.CENTER;
			tv = new TextView(context);
			tv.setLayoutParams(lp);
			tv.setClickable(false);
			tv.setFocusable(false);
			tv.setFocusableInTouchMode(false);
			tv.setTextColor(context.getResources().getColor(R.color.white));
			addView(tv);
		}
	}
	
	public void setImageRsource(int resId) {
		iv.setImageResource(resId);
		iv.setVisibility(View.VISIBLE);
		tv.setVisibility(View.GONE);
	}

	public void setText(String text) {
		tv.setText(text);
		tv.setVisibility(View.VISIBLE);
		iv.setVisibility(View.GONE);
	}

	@Override
	public void setEnabled(boolean enabled) {
		super.setEnabled(enabled);
		iv.setEnabled(enabled);
		tv.setEnabled(enabled);
	}

}
